package com.yun.demo.service;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.yun.demo.mapper.PersonMapper;
import com.yun.demo.mapper.UserMapper;
import com.yun.domain.entity.Person;
import com.yun.domain.entity.User;
import com.yun.util.RestResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class DemoService {
    static Integer name = 0;

    @Resource
    UserMapper userMapper;

    @Resource
    PersonMapper personMapper;
    @Transactional(rollbackFor = Exception.class)
    public RestResult<Integer> serviceTest() {
        User user = new User();
        user.setId(IdWorker.get32UUID());
        user.setName("name"+name++);
        int i = 1/0;
        userMapper.insertUser(user);
        Person person = new Person();
        person.setId(user.getId());
        person.setName(user.getName());
        personMapper.insertPerson(person);
        return RestResult.success();
    }
}
